import user.UsersDAO;
import user.UsersImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 彬彬
 * 用于配置登录前后端，数据交互
 */
@WebServlet(name = "LoginServlet", urlPatterns = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        UsersDAO usersDAO = new UsersImpl();
        System.out.println(username + "\t" +password);
        System.out.println(usersDAO.Login(username, password));
        String html = "";
        if(usersDAO.Login(username, password)){
//        if(("guibin").equals(username) && ("123456").equals(password)){
            resp.sendRedirect("./welcome.html");
            System.out.println("登录成功");
            System.out.println("username:"+username+"\npassword:"+password);
        }else{
            resp.sendRedirect("./login.html");
            System.out.println("登录失败");
            System.out.println("username:"+username+"\npassword:"+password);
        }
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }
}
